package com.zx.BookSeaReader.greendao.entity;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.JoinEntity;
import org.greenrobot.greendao.annotation.NotNull;
import org.greenrobot.greendao.annotation.ToMany;
import org.greenrobot.greendao.annotation.Transient;

import java.io.Serializable;
import java.util.List;

import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.DaoException;
import com.zx.BookSeaReader.greendao.gen.DaoSession;
import com.zx.BookSeaReader.greendao.gen.BookDao;
import com.zx.BookSeaReader.greendao.gen.UserBeanDao;
import com.zx.BookSeaReader.greendao.gen.BookListBeanDao;

/**
 * @Author: ZX
 * @Time: 2020/3/25
 * @Description: 功能描述
 */
@Entity
public class UserBean implements Serializable {
    @Transient
    private static final long serialVersionUID = 1L;

    @Id(autoincrement = true)
    private Long userid;
    @NotNull
    private String username;//用户名
    @NotNull
    private String password;//密码
    private int admin=0;//是否是管理员
    private String gender;//性别

    @ToMany
    @JoinEntity(
            entity = SubscribeBean.class,
            sourceProperty = "userid",
            targetProperty = "bookid"
    )
    private List<Book> books;

    @ToMany
    @JoinEntity(
            entity = BookListSubscribe.class,
            sourceProperty = "userid",
            targetProperty = "bookListid"
    )
    private List<BookListBean> bookListBeans;

    /** Used to resolve relations */
    @Generated(hash = 2040040024)
    private transient DaoSession daoSession;

    /** Used for active entity operations. */
    @Generated(hash = 83707551)
    private transient UserBeanDao myDao;



    @Generated(hash = 640183116)
    public UserBean(Long userid, @NotNull String username, @NotNull String password,
            int admin, String gender) {
        this.userid = userid;
        this.username = username;
        this.password = password;
        this.admin = admin;
        this.gender = gender;
    }
    @Generated(hash = 1203313951)
    public UserBean() {
    }
    public Long getUserid() {
        return this.userid;
    }
    public void setUserid(Long userid) {
        this.userid = userid;
    }
    public String getUsername() {
        return this.username;
    }
    public void setUsername(String username) {
        this.username = username;
    }
    public String getPassword() {
        return this.password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    public int getAdmin() {
        return this.admin;
    }
    public void setAdmin(int admin) {
        this.admin = admin;
    }
    public String getGender() {
        return this.gender;
    }
    public void setGender(String gender) {
        this.gender = gender;
    }
    /**
     * To-many relationship, resolved on first access (and after reset).
     * Changes to to-many relations are not persisted, make changes to the target entity.
     */
    @Generated(hash = 835438861)
    public List<Book> getBooks() {
        if (books == null) {
            final DaoSession daoSession = this.daoSession;
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            BookDao targetDao = daoSession.getBookDao();
            List<Book> booksNew = targetDao._queryUserBean_Books(userid);
            synchronized (this) {
                if (books == null) {
                    books = booksNew;
                }
            }
        }
        return books;
    }
    /** Resets a to-many relationship, making the next get call to query for a fresh result. */
    @Generated(hash = 353255226)
    public synchronized void resetBooks() {
        books = null;
    }
    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#delete(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 128553479)
    public void delete() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.delete(this);
    }
    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#refresh(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 1942392019)
    public void refresh() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.refresh(this);
    }
    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#update(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 713229351)
    public void update() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.update(this);
    }
    /** called by internal mechanisms, do not call yourself. */
    @Generated(hash = 1491512534)
    public void __setDaoSession(DaoSession daoSession) {
        this.daoSession = daoSession;
        myDao = daoSession != null ? daoSession.getUserBeanDao() : null;
    }
    /**
     * To-many relationship, resolved on first access (and after reset).
     * Changes to to-many relations are not persisted, make changes to the target entity.
     */
    @Generated(hash = 35631584)
    public List<BookListBean> getBookListBeans() {
        if (bookListBeans == null) {
            final DaoSession daoSession = this.daoSession;
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            BookListBeanDao targetDao = daoSession.getBookListBeanDao();
            List<BookListBean> bookListBeansNew = targetDao._queryUserBean_BookListBeans(userid);
            synchronized (this) {
                if (bookListBeans == null) {
                    bookListBeans = bookListBeansNew;
                }
            }
        }
        return bookListBeans;
    }
    /** Resets a to-many relationship, making the next get call to query for a fresh result. */
    @Generated(hash = 439759298)
    public synchronized void resetBookListBeans() {
        bookListBeans = null;
    }
}
